layui.use(top.layuiuse,
    function () {
        var form = layui.form;
        var watermark = layui.watermark;
        var tabs = layui.tabs;
        var kaPublic = layui.kaPublic;
        var kahtml = layui.kahtml;
        var $ = layui.jquery;
        var kaAjax = layui.kaAjax;
        var kaBgUrl = layui.kaBgUrl;
        var kaLog = layui.kaLog;
        var kaLanguage = layui.kaLanguage;
        var kaForm = layui.kaForm;
        var kaInterval = layui.kaInterval;
        var kaPreviewText = layui.kaPreviewText;
        //公共
        var bodyUrl = kaPublic.initBodySetUp();
        //加载水印
        loadingWatermark(watermark, { color: "#fff", type: 1, opacity: 0.1 });
        // 注册storage
        localStorage.setItem("kaPreviewTextHtml_" + bodyUrl.id, bodyUrl.id);
        // 初始化监听
        kaPreviewText.init(bodyUrl.id);
        var previewTextCodeHtmlMap = new Map();
        previewTextCodeHtmlMap.set(bodyUrl.id, "");
        window.addEventListener("storage", function (event) {
            if (event.key === bodyUrl.id) {
                //加载内容
                var previewTextCodeHtml = "";
                var dataJsonStr = localStorage.getItem(bodyUrl.id);//获取出入的JSON
                if (dataJsonStr != undefined && dataJsonStr != null && dataJsonStr != "") {
                    var dataJson = JSON.parse(dataJsonStr);
                    previewTextCodeHtml = dataJson.content;
                    // 判断 是追加还是覆盖
                    var code = "";
                    if (dataJson.type == 1) { //追加
                        var codeStart = previewTextCodeHtmlMap.get(bodyUrl.id);
                        var br = "\r\n\r\n********************************************************************\r\n";
                        if (codeStart == "") {
                            code = previewTextCodeHtml
                        } else {
                            code = codeStart + br + previewTextCodeHtml
                        }
                        previewTextCodeHtmlMap.set(bodyUrl.id, code);
                    } else if (dataJson.type == 2) { //覆盖
                        code = previewTextCodeHtml;
                    }
                    //渲染代码
                    layui.code({ elem: '#previewTextCode', code: code });
                    localStorage.removeItem(bodyUrl.id);
                }
            }
        });
        //渲染代码
        layui.code({ elem: '#previewTextCode' });
    }
)